package com.cx.core.dict.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class DictService {

    private static ConcurrentHashMap<String, ConcurrentHashMap<String, String>> dictMap = new ConcurrentHashMap<>();

    public String getValue(String dictType, String dictValue){
        return dictMap.get(dictType).get(dictValue);
    }

    public static void validateValue(String dictType, String dictValue){
        if(!dictMap.containsKey(dictType)){
            throw new RuntimeException();
        }
        if(!dictMap.get(dictType).containsKey(dictValue)){
            throw new RuntimeException();
        }
    }

    @PostConstruct
    public void initData() {
        //数据库获取数据

        //将数据更新到map中

    }
}
